﻿using Slex;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Test.Scenes {
    public partial class SinLine : UserControl {
        public SinLine() {
            InitializeComponent();
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e) {
            var x = new Ellipse();
            x.RenderTransform = new TranslateTransform();
            x.Width = x.Height = 15;
            x.Fill = Brushs.Green.ToBrush();
            var dm1 = new DoubleAnimation();
            Storyboard.SetTarget(dm1, x);
            Storyboard.SetTargetProperty(dm1, new PropertyPath("(Ellipse.RenderTransform).(TranslateTransform.X)"));
            var dm2 = new DoubleAnimation();
            Storyboard.SetTarget(dm2, x);
            Storyboard.SetTargetProperty(dm2, new PropertyPath("(Ellipse.RenderTransform).(TranslateTransform.Y)"));
            //
            dm1.From = 50;
            dm1.To = this.LayoutRoot.ActualWidth - 50;
            dm2.From = 0;
            dm2.To = 150;
            dm2.AutoReverse = true;
            dm2.Duration = TimeSpan.FromSeconds(1);
            dm2.RepeatBehavior = new RepeatBehavior(5);
            dm1.Duration = TimeSpan.FromSeconds(10);
            dm2.EasingFunction = new System.Windows.Media.Animation.SineEase {
                EasingMode=EasingMode.EaseInOut
            };
            //
            sb.Children.Add(dm1);
            sb.Children.Add(dm2);
            dm1.Completed += dm1_Completed;
            //
            Canvas.SetTop(x, 200);
            Canvas.SetLeft(x, 50);
            this.LayoutRoot.Children.Add(x);
            this.sb.Begin();
        }

        void dm1_Completed(object sender, EventArgs e) {
            sb.Begin();
        }
    }
    public class SinFun:System.Windows.Media.Animation.EasingFunctionBase {
        public SinFun() {
        }
        protected override double EaseInCore(double normalizedTime) {
            return 0.0;
        }
    }
}
